package com.maimang.platform.controller.system;

import com.maimang.platform.annotation.Log;
import com.maimang.platform.base.BaseController;
import com.maimang.platform.base.Result;
import com.maimang.platform.common.entity.SysFileChannel;
import com.maimang.platform.enums.BusinessType;
import com.maimang.platform.page.TableDataInfo;
import com.maimang.platform.common.service.SysFileChannelService;
import com.maimang.platform.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件通道信息操作处理
 *
 * @author Rocky
 * @date 2019-01-19
 */
@Controller
@RequestMapping("/system/fileChannel")
@Api(value = "文件通道", description = "文件通道信息操作处理")
public class SysFileChannelController extends BaseController {
	private String prefix = "system/fileChannel";

	@Autowired
	private SysFileChannelService fileChannelService;

	@RequiresPermissions("system:fileChannel:view")
	@GetMapping()
	public String fileChannel() {
		return prefix + "/fileChannel";
	}

	/**
	 * 查询文件通道列表
	 */
	@RequiresPermissions("system:fileChannel:list")
	@ApiOperation(value = "文件通道列表", notes = "查询文件通道列表，返回前端表格数据信息")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysFileChannel fileChannel) {
		startPage();
		List<SysFileChannel> list = fileChannelService.selectSysFileChannelList(fileChannel);
		return getDataTable(list);
	}


	/**
	 * 导出文件通道列表
	 */
	@RequiresPermissions("system:fileChannel:export")
	@ApiOperation(value = "导出通道", notes = "导出文件通道信息列表数据到Excel表格")
	@PostMapping("/export")
	@ResponseBody
	public Result export(SysFileChannel fileChannel) {
		List<SysFileChannel> list = fileChannelService.selectSysFileChannelList(fileChannel);
		ExcelUtil<SysFileChannel> util = new ExcelUtil<>(SysFileChannel.class);
		return util.exportExcel(list, "fileChannel");
	}

	/**
	 * 新增通道文件
	 *
	 * @param channelCode
	 * @param modelMap
	 * @return
	 */
	@GetMapping("/addfile")
	public String addFile(Long channelCode, ModelMap modelMap) {
		modelMap.put("channelCode", channelCode);
		return prefix + "/addfile";
	}

	/**
	 * 新增文件通道
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存文件通道
	 */
	@RequiresPermissions("system:fileChannel:add")
	@Log(title = "文件通道", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(SysFileChannel fileChannel) {
		return toResult(fileChannelService.insertSysFileChannel(fileChannel));
	}

	/**
	 * 修改文件通道
	 */
	@GetMapping("/edit/{channelId}")
	public String edit(@PathVariable("channelId") Long channelId, ModelMap modelMap) {
		SysFileChannel fileChannel = fileChannelService.selectSysFileChannelById(channelId);
		modelMap.put("fileChannel", fileChannel);
		return prefix + "/edit";
	}

	/**
	 * 修改保存文件通道
	 */
	@RequiresPermissions("system:fileChannel:edit")
	@Log(title = "文件通道", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(SysFileChannel fileChannel) {
		return toResult(fileChannelService.updateSysFileChannel(fileChannel));
	}

	/**
	 * 删除文件通道
	 */
	@RequiresPermissions("system:fileChannel:remove")
	@Log(title = "文件通道", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public Result remove(String ids) {
		return toResult(fileChannelService.deleteSysFileChannelByIds(ids));
	}

	/**
	 * 删除对应的播放文件
	 *
	 * @param ids
	 * @return
	 */
	@PostMapping("/removeFile")
	@ResponseBody
	public Result removeFile(String ids) {
		return toResult(fileChannelService.removeFile(ids));
	}

	@PostMapping("/saveLimit")
	@ResponseBody
	public Result saveLimit(String ids) {
		return toResult(fileChannelService.saveLimit(ids));
	}

}